package com.oocl.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.oocl.dao.DeliverInfoDao;
import com.oocl.dao.base.BaseDao;
import com.oocl.dao.base.BaseJPADaoUtil;
import com.oocl.entity.Clients;
import com.oocl.entity.DeliverInfo;
import com.oocl.service.DeliverInfoService;
import com.oocl.util.VoUtil;

@Service("deliverInfoService")
public class DeliverInfoServiceImpl implements DeliverInfoService {

	@Resource(name="baseDao")
	private BaseDao baseDao;
	@Resource(name="deliverInfoDao")
	private DeliverInfoDao deliverInfoDao;
	
	
	
	/*
	 * @Method:addDeliverInfo
	 * @function: insert new deliver info to db
	 * @param:DeliverInfo deliverInfo
	 * @Author:Wendy
	 * @time:2017-8-13
	 * @see com.oocl.service.DeliverInfoService#addDeliverInfo(com.oocl.entity.DeliverInfo)
	 */
	@Override
	@Transactional
	public DeliverInfo addDeliverInfo(DeliverInfo deliverInfo,String cid) {
		// TODO Auto-generated method stub
		Clients client = (Clients) baseDao.find(Clients.class, cid);
		DeliverInfo d=new DeliverInfo();
		deliverInfo.setClient(client);
		d=(DeliverInfo) baseDao.persist(deliverInfo);
		return d;
	}

	
	/*
	 * @Method:loadAllDeliverInfoByCid
	 * @function: find the deliverInfo list of the customer whose id is 'cid'
	 * @param:String cid
	 * @Author:Wendy
	 * @time:2017-8-13
	 * 
	 */
	@Override
	@Transactional
	public List<DeliverInfo> loadAllDeliverInfoByCid(String cid) {
		// TODO Auto-generated method stub
		List<DeliverInfo> dlist=new ArrayList<DeliverInfo>();
		dlist=deliverInfoDao.loadAllDeliverInfoByCid(cid);
		return dlist;
	}

	/*
	 * @Method:deleteDeliverInfo
	 * @function: delete the DeliverInfo by id
	 * @param:String id
	 * @Author:Wendy
	 * @time:2017-8-13
	 * 
	 */
	@Override
	@Transactional
	public void deleteDeliverInfo(String id) {
		// TODO Auto-generated method stub
		baseDao.delete(DeliverInfo.class, id);
		
	}
	
	/*
	 * @Method:loadDeliverInfoById
	 * @function: find the deliverInfo by id
	 * @param:String id
	 * @Author:Wendy
	 * @time:2017-8-13
	 * 
	 */

	@Override
	@Transactional
	public DeliverInfo loadDeliverInfoById(String id) {
		// TODO Auto-generated method stub
		DeliverInfo d=new DeliverInfo();
		d=(DeliverInfo) baseDao.find(DeliverInfo.class, id);
		return d;
	}

	/*
	 * @Method:updateDeliverInfo
	 * @function: update the deliverInfo
	 * @param:DeliverInfo deliverInfo
	 * @Author:Wendy
	 * @time:2017-8-13
	 * 
	 */
	@Override
	@Transactional
	public DeliverInfo updateDeliverInfo(DeliverInfo deliverInfo) {
		// TODO Auto-generated method stub
		DeliverInfo d=new DeliverInfo();
		d=(DeliverInfo) baseDao.update(deliverInfo);
		return d;
	}
	@Override
	@Transactional
	public DeliverInfo transformDeliverInfo(DeliverInfo deliverInfo){
		DeliverInfo dInfo = loadDeliverInfoById(deliverInfo.getDid());
		dInfo.setAddr(deliverInfo.getAddr());
		dInfo.setContact(deliverInfo.getContact());
		dInfo.setTel(deliverInfo.getTel());
		return dInfo;
	}

}
